package com.ttbj.core.session;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * MMSessionImpl实现类
 * 
 * @Author Daniel
 * @Date 2014-12-1
 */
public class CommonSessionImpl implements CommonSession {
	protected static final Logger logger = LoggerFactory
			.getLogger(CommonSessionImpl.class);
	/** Session最大超时时间 */
	private static final int maxInactiveInterval = 900;

	/** sessionKey */
	private String sessionKey;

	public CommonSessionImpl() {
	}

	public CommonSessionImpl(String sessionId) {
		this.sessionKey = sessionId;
	}

	@Override
	public Object getAttribute(HttpServletRequest request, String key) {
		return request.getSession(true).getAttribute(key);
	}

	@Override
	public void removeAttribute(HttpServletRequest request, String key) {
		request.getSession(true).removeAttribute(key);
	}

	@Override
	public void setAttribute(HttpServletRequest request, String key, Object obj) {
		request.getSession(true).setAttribute(key, obj);
	}

	@Override
	public void setAttribute(HttpServletRequest request, String key,
			Object obj, long liveTime) {
		HttpSession session = request.getSession(true);
		session.setMaxInactiveInterval(maxInactiveInterval);
		session.setAttribute(key, obj);
	}
}